import requests
from bs4 import BeautifulSoup
import re
import json

url = 'https://www.kuaidaili.com/free/intr'
headers = {'User-Agent': 'Mozilla/5.0'}
def get_ip():
    try:
        r = requests.get(url, headers=headers)
        r.raise_for_status()  # Check for any HTTP errors
        return r.text
    except requests.exceptions.RequestException as e:
        print(f'An error occurred: {e}')

html=get_ip()
soup = BeautifulSoup(html, 'lxml')

j=re.findall(r'const fpsList =(.*?"}]);',html)
list=j[0]

fd=open('ip.json', 'w')
fd.write(list)
fd.close()
print('写入完成')